import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { CoreModule } from '../core.module';
import { CommonService } from './common.service';
import { ApiService, urlService } from '../api';
import { CommonResponse, ResWalletBalance } from '../../model';
import { retry } from 'rxjs/operators';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: CoreModule
})
export class UserWalletService implements CommonService {

  getUserWalletBalanceForWithdrawal(params: { coinName: string}): Observable<CommonResponse<ResWalletBalance>> {
    return this.api.post<CommonResponse<ResWalletBalance>>(
      this.getUrl('获取当前币名称 余额,转账手续费 等信息'),
      params,
    ).pipe(
      retry(3)
    );
  }

  constructor(
    private api: ApiService
  ) { }

  error(error: any): void {
    this.api.goToWhere(error);
  }
  getUrl(apiName: string): string {
    return urlService(environment.type, apiName);
  }
}
